﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMSConnector.Authentication;
using SMSConnector;
using SMSConnector.Providers.Clikatell;

namespace SMSServices.Helpers
{
    /// <summary>
    /// For authorization logic
    /// </summary>
    public class AuthorizationHelper
    {
        private static AuthenticationParameters _params;
        private static string _clickatellSessionId;

        /// <summary>
        /// Returns current AuthenticationParameters
        /// </summary>
        public static AuthenticationParameters GetAuthParameters(string username, string password)
        {
            if (_params == null)
            {
                _params = ConnectorHelper.GetAuthenticationParameters(username, password);
            }
            return _params;
        }

        /// <summary>
        /// Returns clickatell session identifier
        /// </summary>
        public static string GetClickatellSessionId(int applicationId, string username, string password)
        {
            if (_clickatellSessionId == null)
            {
                _clickatellSessionId = ClickatellProviderHelper.GetSessionId(applicationId, username, password);
            }
            else
            {
                if (!ClickatellProviderHelper.SessionActual(_clickatellSessionId))
                {
                    _clickatellSessionId = ClickatellProviderHelper.GetSessionId(applicationId, username, password);
                }
            }
            return _clickatellSessionId;
        }
    }
}
